package com.pine.manager.pineframework;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.pine.dao.pineframework.entity.SysLog;
import com.pine.dao.pineframework.mapper.SysLogMapper;
import com.pine.manager.core.BaseManager;
import com.pine.manager.pineframework.bo.SysLogBo;
import com.pine.manager.pineframework.convertors.SysLogConvertor;
import com.pine.manager.pineframework.query.SysLogQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 系统日志表 管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Component
public class SysLogManager extends BaseManager<SysLogMapper, SysLog, Long, SysLogBo, SysLogQuery, SysLogConvertor> {

    @Resource
    private SysLogConvertor sysLogConvertor;

    @Override
    public LambdaQueryWrapper<SysLog> encapsulateQueryWrapper(SysLogQuery query) {
        LambdaQueryWrapper<SysLog> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getLogId()), SysLog::getLogId, query.getLogId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRequestIp()), SysLog::getRequestIp, query.getRequestIp());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getLogType()), SysLog::getLogType, query.getLogType());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getDescription()), SysLog::getDescription, query.getDescription());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getClassPath()), SysLog::getClassPath, query.getClassPath());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getActionMethod()), SysLog::getActionMethod, query.getActionMethod());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getHttpMethod()), SysLog::getHttpMethod, query.getHttpMethod());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRequestParam()), SysLog::getRequestParam, query.getRequestParam());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getResponseParam()), SysLog::getResponseParam, query.getResponseParam());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRequestUri()), SysLog::getRequestUri, query.getRequestUri());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getStartTimeStart()), SysLog::getStartTime, query.getStartTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getStartTimeEnd()), SysLog::getStartTime, query.getStartTimeEnd());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getEndTimeStart()), SysLog::getEndTime, query.getEndTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getEndTimeEnd()), SysLog::getEndTime, query.getEndTimeEnd());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCostTime()), SysLog::getCostTime, query.getCostTime());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getError()), SysLog::getError, query.getError());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUserId()), SysLog::getCreateUserId, query.getCreateUserId());

        return queryWrapper;
    }
}
